package com.alibaba.citrus.ots.platform.enhance.service.impl;

import com.alibaba.citrus.ots.platform.enhance.service.ScItemGroupMeshFlowService;
import com.alibaba.cz.base.tool.page.PageResult;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.otsplatformenhance.api.group.scitemgroupquery.service.ScItemGroupQueryService;
import com.epoch.app.otsplatformenhance.api.group.scitemgroupwrite.service.ScItemGroupWriteService;
import com.epoch.app.otsplatformenhance.dto.request.CreateScItemGroupRequest;
import com.epoch.app.otsplatformenhance.dto.request.IdQueryRequest;
import com.epoch.app.otsplatformenhance.dto.request.QueryScItemGroupRequest;
import com.epoch.app.otsplatformenhance.dto.response.ScItemGroupResponse;
import com.epoch.app.otsplatformenhance.sdo.ScItemGroupSDO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zls
 * @description: TODO
 * @date 2021/9/8 19:05
 */
@Component
public class ScItemGroupMeshFlowServiceImpl implements ScItemGroupMeshFlowService {

    @Resource
    private ScItemGroupQueryService scItemGroupQueryService;

    @Resource
    private ScItemGroupWriteService scItemGroupWriteService;

    @Override
    public Result<String> createScItemGroup(CreateScItemGroupRequest request) {
        ScItemGroupSDO scItemGroupSDO = new ScItemGroupSDO();
        BeanUtils.copyProperties(request, scItemGroupSDO);
        return scItemGroupWriteService.createScItemGroup(scItemGroupSDO);
    }

    @Override
    public Result<ScItemGroupResponse> getScItemGroupById(IdQueryRequest request) {
        return scItemGroupQueryService.getScItemGroupById(request);
    }

    @Override
    public Result<PageResult<List<ScItemGroupResponse>>> pageQueryScItemGroupList(QueryScItemGroupRequest request) {
        Result<List<ScItemGroupSDO>> pageResultResult = scItemGroupQueryService.pageQueryScItemGroupList(request);
        List<ScItemGroupSDO> content = pageResultResult.getResult();
        List<ScItemGroupResponse> collect = content.stream().map(scItemGroupSDO -> {
            ScItemGroupResponse scItemGroupResponse = new ScItemGroupResponse();
            BeanUtils.copyProperties(scItemGroupSDO, scItemGroupResponse);
            return scItemGroupResponse;
        }).collect(Collectors.toList());
        return Result.success(PageResult.of(collect, pageResultResult.getTotal()));
    }
}
